home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / util / moni / ErrorLog15.lha / ErrorLog / Src / DevInfo.c next >
Encoding:
C/C++ Source or Header  |  2002-01-06  |  5.1 KB  |  178 lines

  1. /*
  2. **    $RCSfile: DevInfo.c,v $
  3. **    $Filename: DevInfo.c $
  4. **    $Revision: 1.2 $
  5. **    $Date: 2002/01/05 18:17:13 $
  6. **
  7. **    DevInfo source file (version 1.2 beta) 
  8. **
  9. **    (C) Copyright 1993-2001 by Etienne Vogt
  10. */
  11.  
  12. #include <exec/types.h>
  13. #include <exec/memory.h>
  14. #include <exec/ports.h>
  15. #include <exec/io.h>
  16. #include <exec/alerts.h>
  17. #include <dos/dos.h>
  18. #include <dos/rdargs.h>
  19. #include <workbench/startup.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22.  
  23. #define __USE_SYSBASE
  24. #include <proto/exec.h>
  25. #include <proto/dos.h>
  26.  
  27. #include "errorlog.h"
  28.  
  29. ULONG __saveds main(void);
  30. static void clearall(void);
  31. #ifdef __SASC
  32. void __regargs __chkabort(void);
  33. #endif
  34.  
  35. /* Global variables */
  36.  
  37. struct ExecBase *SysBase;
  38. static struct WBStartup *wbmsg;
  39. static struct RDArgs *myrda;
  40.  
  41. static STRPTR version = "$VER: DevInfo 1.2 beta (29.12.2001)";
  42. static STRPTR template = "DEVICE,FULL/S";
  43.  
  44. #define OPT_DEVICE    0
  45. #define OPT_FULL    1
  46. #define OPTMAX        2
  47.  
  48.  
  49. ULONG __saveds main(void)
  50. {
  51.   struct Process *myproc;
  52.   LONG opts[OPTMAX];
  53.  
  54.   struct HellGate *hgate;
  55.   struct DoomNode *dnode, *copnodes, *DNp;
  56.   int i;
  57.   ULONG opcount, logcount, errorcount, abortcount;
  58.   APTR pbegIO, pabIO, dcb;
  59.   ULONG rc = 0;
  60.   BOOL found = FALSE;
  61.  
  62.   SysBase = *(struct ExecBase **)4;
  63.   DOSBase = NULL;
  64.   wbmsg = NULL;
  65.   myrda = NULL;
  66.  
  67.   myproc = (struct Process *)FindTask(NULL);
  68.   if ((DOSBase = (struct DosLibrary *)OpenLibrary("dos.library",37)) == NULL)
  69.   { Alert(AT_Recovery|AG_OpenLib|AO_DOSLib);
  70.     clearall();
  71.     return(100);
  72.   }
  73.   if (!(myproc->pr_CLI))        /* If started from WB, exit cleanly */
  74.   { WaitPort(&(myproc->pr_MsgPort));
  75.     wbmsg = (struct WBStartup *)GetMsg(&(myproc->pr_MsgPort));
  76.     clearall();
  77.     return(20);
  78.   }
  79.   memset((char *)opts, 0, sizeof(opts));
  80.   if ((myrda = ReadArgs(template, opts, NULL)) == NULL)
  81.   { PrintFault(IoErr(),NULL);
  82.     clearall();
  83.     return(20);
  84.   }
  85.  
  86.   if (opts[OPT_DEVICE])
  87.   {
  88.     UBYTE *colon;
  89.  
  90.     if (colon = (UBYTE *)strchr((const char *)opts[OPT_DEVICE],':')) *colon = (UBYTE)0;
  91.   }
  92.  
  93.   Forbid();
  94.   if (hgate = (struct HellGate *)FindSemaphore("ErrorLog.HellGate"))
  95.   { ObtainSemaphoreShared(&hgate->hg_SigSem);
  96.     Permit();
  97.     logcount = hgate->hg_LogCount;
  98.     errorcount = hgate->hg_ErrorCount;
  99.     opcount = hgate->hg_OpCount;
  100.     abortcount = hgate->hg_AbortCount;
  101.     pbegIO = (APTR)hgate->hg_PatchBeginIO;
  102.     pabIO = (APTR)hgate->hg_PatchAbortIO;
  103.     dcb = (APTR)hgate->hg_DummyCopyBuff;
  104.     if (copnodes = (struct DoomNode *)AllocVec(logcount * sizeof(struct DoomNode), MEMF_PUBLIC))
  105.     { for (i = 0, DNp = copnodes, dnode = (struct DoomNode *)hgate->hg_DoomList.lh_Head;
  106.        i < logcount;
  107.        dnode = (struct DoomNode *)dnode->dn_Link.ln_Succ, i++, DNp++)
  108.       { CopyMem(dnode, DNp, sizeof(struct DoomNode));
  109.       }
  110.       ReleaseSemaphore(&hgate->hg_SigSem);
  111.       PutStr("\n");
  112.       if (opts[OPT_FULL])
  113.       { Printf("Currently Logged Devices/units : %ld\n",logcount);
  114.     Printf("Total Operations completed     : %ld\n",opcount);
  115.     Printf("Total Operations aborted       : %ld\n",abortcount);
  116.     Printf("Total Errors on Logged units   : %ld\n",errorcount);
  117.     Printf("Patched BeginIO() code         : %08lx\n",pbegIO);
  118.     Printf("Patched AbortIO() code         : %08lx\n",pabIO);
  119.     Printf("Dummy CopyBuff() routine       : %08lx\n",dcb);
  120.     Printf("\n");
  121.       }
  122.       for (i = 0, DNp = copnodes; i < logcount; i++, DNp++)
  123.     if (!opts[OPT_DEVICE] || !strnicmp((char *)opts[OPT_DEVICE], DNp->dn_Link.ln_Name, DNAME_SIZE))
  124.     { found = TRUE;
  125.       Printf("%.8s : Device %.24s, Unit %ld, ", DNp->dn_Link.ln_Name, &DNp->dn_DeviceName, DNp->dn_UnitNum);
  126.       if (DNp->dn_Flags & DNF_ENABLED) PutStr("enabled, ");
  127.       else PutStr("disabled, ");
  128.       if (DNp->dn_Flags & DNF_LOGERRORS) PutStr("error logging on\n");
  129.       else PutStr("error logging off\n");
  130.       Printf("Operations completed    : %lu\n",DNp->dn_OpCount);
  131.       Printf("Operations pending      : %lu\n",DNp->dn_ActiveCount);
  132.       Printf("Error count             : %lu\n",(LONG)DNp->dn_ErrorCount);
  133.       if (opts[OPT_FULL])
  134.       { Printf("DoomList priority       : %ld\n",(LONG)DNp->dn_Link.ln_Pri);
  135.         Printf("Device base address     : %08lx\n",DNp->dn_IOReq.ios2_Req.io_Device);
  136.         Printf("Unit base address       : %08lx\n",DNp->dn_IOReq.ios2_Req.io_Unit);
  137.         Printf("Device Type             : %lu\n",(ULONG)DNp->dn_DevType);
  138.         Printf("Device SubType          : %lu\n",(ULONG)DNp->dn_DevSubType);
  139.         Printf("IORequest size (bytes)  : %lu\n",(ULONG)DNp->dn_IOSize);
  140.         Printf("Original BeginIO() code : %08lx\n",DNp->dn_OrigBeginIO);
  141.         Printf("Original AbortIO() code : %08lx\n",DNp->dn_OrigAbortIO);
  142.       }
  143.       PutStr("\n");
  144.     } 
  145.       FreeVec(copnodes);
  146.       if (opts[OPT_DEVICE] && !found) Printf("Error : Couldn't find DoomNode %s\n",(STRPTR)opts[OPT_DEVICE]);
  147.     }
  148.     else 
  149.     { ReleaseSemaphore(&hgate->hg_SigSem);
  150.       Printf("Error : Not enough memory to scan DoomList\n"); 
  151.       rc = 20;
  152.     }
  153.   }
  154.   else
  155.   { Permit();
  156.     Printf("Error : The ErrorLog.daemon is not running.\n");
  157.     rc = 10;
  158.   }
  159.   clearall();
  160.   return rc;
  161. }
  162.  
  163. static void clearall(void)
  164. {
  165.   if (myrda) FreeArgs(myrda);
  166.   if (DOSBase) CloseLibrary((struct Library *)DOSBase);
  167.   if (wbmsg)
  168.   { Forbid();
  169.     ReplyMsg((struct Message *)wbmsg);
  170.   }
  171. }
  172.  
  173. #ifdef __SASC
  174. void __regargs __chkabort(void)
  175. {
  176. }
  177. #endif
  178.